package com.example.animation_demo;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;



public class MainAbility extends Ability implements Component.ClickedListener {
    private Button animator_frame_button, animator_value_button,
            animator_property_button,animator_group_button;

    private String AnimationFrame ="com.example.animation_demo.AnimationFrameAbility";

    private String AnimatorValue ="com.example.animation_demo.AnimatorValueAbility";

    private String AnimatorProperty="com.example.animation_demo.AnimatorPropertyAbility";

    private String AnimatorGroup="com.example.animation_demo.AnimatorGroupAbility";





    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initview();
    }

    private void initview() {
        animator_frame_button= (Button) findComponentById(ResourceTable.Id_animator_frame_button);
        animator_value_button= (Button) findComponentById(ResourceTable.Id_animator_value_button);
        animator_property_button= (Button) findComponentById(ResourceTable.Id_animator_property_button);
        animator_group_button= (Button) findComponentById(ResourceTable.Id_animator_group_button);
        animator_frame_button.setClickedListener(this);
        animator_value_button.setClickedListener(this);
        animator_property_button.setClickedListener(this);
        animator_group_button.setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()){
            case ResourceTable.Id_animator_frame_button:
              intentAbility(AnimationFrame);
            break;
            case ResourceTable.Id_animator_value_button:
              intentAbility(AnimatorValue);
                break;
            case ResourceTable.Id_animator_property_button:
                intentAbility(AnimatorProperty);
                break;

            case ResourceTable.Id_animator_group_button:
                intentAbility(AnimatorGroup);
                break;

        }
    }



    private  void  intentAbility(String abilityName){
        Intent intent = new Intent();
        // 通过Intent中的OperationBuilder类构造operation对象，指定设备标识（空串表示当前设备）、应用包名、Ability名称
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                 .withBundleName("com.example.animation_demo")
                .withAbilityName(abilityName)
                .build();
        // 把operation设置到intent中
        intent.setOperation(operation);
        startAbility(intent);
    }




}
